#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#include "aatracker.h"
#include "networkhandler.h"
#include "bencoder.h"
#include  "trackerlogger.h"

int sendHttpOKStatus(int sock){

    int sentBytes = send(sock, "HTTP/1.1 200 OK\n\n", 17, 0 );

    if (sentBytes < 17 ){

            logError("sendHttpOKStatus()", "error sending HTTP status 200 to client", __FILE__, __LINE__, errno);

        return ERROR_SENDING_HTTP_OK_STATUS;
    }

    return OK;
}

int sendTrackerBencodedResponse(int sock, BencodedResponse *br){

    int sentBytes = send(sock, br->str, br->bencodedResponseLength, 0 );

    if (sentBytes < br->bencodedResponseLength ){

            logError("sendTrackerBencodedResponse()", "error sending bencoded response to client", __FILE__, __LINE__, errno);

        return ERROR_SENDING_BENCODED_RESPONSE;
    }

    return OK;
}
